<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加</title>
    <link rel="stylesheet" th:href="@{/layuiadmin/layui/css/layui.css}" media="all">
</head>
<body>
    <div class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
        <input type="hidden" name="id" th:if="${company}" th:value="${company.id}">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input th:value="${company != null}?${company.name}:''" type="text" name="name" lay-verify="required" placeholder="请输入公司名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">公司代码</label>
            <div class="layui-input-inline">
                <input th:value="${company != null}?${company.code}:''" type="text" name="code"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">公司信息</label>
            <div class="layui-input-inline">
                <input th:value="${company != null}?${company.message}:''" type="text" name="message" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">公司网址</label>
            <div class="layui-input-inline">
                <input th:value="${company != null}?${company.website}:''" type="text" name="website"   autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">公司电话</label>
            <div class="layui-input-inline">
                <input th:value="${company != null}?${company.phone}:''" type="text" name="phone"   autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">金牌用户</label>
            <div class="layui-input-inline">
                <input th:value="${company != null}?${company.goldUser}:''" type="text" name="goldUser" placeholder="请输入金牌用户折扣"   autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">银牌用户</label>
            <div class="layui-input-inline">
                <input th:value="${company != null}?${company.silverUser}:''" type="text" name="silverUser" placeholder="请输入银牌用户折扣"   autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">儿童</label>
            <div class="layui-input-inline">
                <input th:value="${company != null}?${company.childUser}:''" type="text" name="childUser" placeholder="请输入儿童用户折扣"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button th:text="${company != null}?'立即修改':'立即添加'" class="layui-btn" lay-submit="" lay-filter="addadmin">立即添加</button>
                <button th:if="${company == null}" type="reset" id="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>

    <script th:src="@{/layuiadmin/layui/layui.js}"></script>
    <script>

        layui.use(['form','jquery'], function () {
            var form = layui.form;
            var $ = layui.jquery;
            form.on('submit(addadmin)',function (data) {
                $.ajax({
                    url:'/manager/saveCompany',
                    data:data.field,
                    dataType:'json',
                    type:'post',
                    success:function (data) {
                        if (data.success){
                            layer.msg(data.message);
                            layer.alert(data.message,function(){
                                window.parent.location.reload();//刷新父页面
                                parent.layer.close(index);//关闭弹出层
                            });
                        }else{
                            layer.msg(data.message);
                        }
                    }
                });
                return false;
            })

            //重置
            $("#reset").click(function () {
                $("input").val("");
            })

        });


    </script>
</body>
</html>